<style>
  .header-font {
    font-size: 15px;
    font-weight: bold;
  }
  .line {
    margin: 10px 0;
    width: 100%;
    border: 0.5px solid rgb(218, 218, 218);
  }
  .table {
    margin-top: 10px;
  }
  .paging {
    float:right;
    margin-top:10px;
  }
</style>
<template>
  <div>
    <div class='header-font'>
      <Icon type="md-apps" />
      <span>参数配置</span>
    </div>
    <div class="line"></div>
    <!-- <Button
      icon="md-add"
      type="primary"
      @click="handleClick">
      数据配置
    </Button> -->
    <parameter-config-drawer
      @config-valid="handleEdit">
    </parameter-config-drawer>
    <Table
      class="table"
      :columns="columns"
      :data="sysConfigList"
      :loading="loading"
      border
      >
    </Table>
    <!-- <table-page
      class="paging"
      :dataCount="dataCount"
      @change-page="changePage"
      @change-page-size="changePageSize"
      :pageSize="pageSize">
    </table-page> -->
  </div>
</template>
<script>
import {
  mapActions,
  mapState
} from 'vuex'
import ParameterConfigDrawer from '_c/parameter-config-drawer'
import TablePage from '_c/table-page'
import TableExpand from '_c/table-expand'
export default {
  components: {
    ParameterConfigDrawer,
    TableExpand,
    TablePage
  },
  data () {
    return {
      page: 1,
      title: '系统管理参数配置',
      index: '',
      confirmData: {},
      loading: true,
      columns: [
        {
          type: 'expand',
          width: 50,
          render: (h, params) => {
            return h(TableExpand, {
              props: {
                row: params.row
              }
            })
          }
        },
        // {
        //   title: '序号',
        //   type: 'index2',
        //   width: 80,
        //   align: 'center',
        //   render: (h, params) => {
        //     return h('span', params.index + (this.page - 1) * this.pageSize + 1)
        //   }
        // },
        {
          title: '公司名',
          key: 'title',
          minWidth: 200,
          align: 'center'
        }
        // {
        //   title: '操作',
        //   key: 'cz',
        //   minWidth: 120,
        //   align: 'center',
        //   render: (h, params) => {
        //     return h('div', [
        //       h('Button', {
        //         props: {
        //           type: 'primary',
        //           size: 'small',
        //           ghost: 'ghost'
        //         },
        //         style: {
        //           marginRight: '5px'
        //         },
        //         on: {
        //           click: () => {
        //             this.handleClick(params.row.id, params.row)
        //           }
        //         }
        //       }, '修改')
        //     ])
        //   }
        // }
      ]
    }
  },
  computed: {
    ...mapState({
      sysConfigList: state => state.sysParamsConfig.sysConfigList,
      dataCount: state => state.sysParamsConfig.sysConfigDataCount,
      historyData: state => state.sysParamsConfig.sysConfigHistoryData,
      pageSize: state => state.sysParamsConfig.sysConfigPageSize
    })
  },
  methods: {
    ...mapActions([
      'getSysConfigList',
      'editSysConfigData',
      'getSysConfigCurrentRow',
      'updateCustomerDrawerState',
      'changeSysConfigPage',
      'changeSysConfigPageSize'
    ]),
    handleClick (id, row) {
      // console.log(row)
      let newRow = {}
      this.id = id
      if (row) {
        newRow = Object.assign({}, row)
      }
      this.getSysConfigCurrentRow(newRow)
      this.updateCustomerDrawerState(true)
    },
    async handleEdit (playload) {
      this.loading = true
      // console.log(playload)
      const resp = await this.editSysConfigData(playload)
      if (resp.data.state === '000') {
        this.$Message.success('修改成功')
        this.getSysConfigList({}).then((res) => {
          if (res.data.state === '000') {
            this.loading = false
          }
        })
      } else {
        this.$Message.error(resp.data.msg)
      }
      this.updateCustomerDrawerState(false)
    },
    changePage (index) {
      this.page = index
      this.changeSysConfigPage(index)
    },
    changePageSize (value) {
      this.rows = value
      this.changeSysConfigPageSize(value)
      this.changePage(this.page)
    }
  },
  created () {
    this.getSysConfigList({}).then((res) => {
      if (res.data.state === '000') {
        this.loading = false
      }
    })
  }
}
</script>
